//
//  LBPaySuccessVC.m
//  V-Learn
//
//  Created by Apple on 2019/2/12.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBPaySuccessVC.h"
#import "HomeViewController.h"
#import "CourseDetailsViewController.h"
#import "StudyViewController.h"
@interface LBPaySuccessVC ()

@end

@implementation LBPaySuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)setupUI{
    self.navigationItem.title = @"确认订单";
    self.view.backgroundColor = rgb(242,242,242);
    UIImageView *bgImageView = [[UIImageView alloc] init];
    bgImageView.image = [UIImage imageNamed:@"wk_bg_pay"];
    [self.view addSubview:bgImageView];
    [bgImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(64*kScaleFit);
        make.height.mas_equalTo(150*kScaleFit);
    }];
    
    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 5;
    bgView.layer.masksToBounds = YES;
    [self.view addSubview:bgView];
    [bgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25*kScaleFit);
        make.right.mas_equalTo(-25*kScaleFit);
        make.top.mas_equalTo((70+64)*kScaleFit);
        make.height.mas_equalTo(400*kScaleFit);
    }];
    UIImageView *icon = [[UIImageView alloc] init];
    icon.image = [UIImage imageNamed:@"wk_pay_success"];
    [bgView addSubview:icon];
    [icon makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40*kScaleFit);
        make.centerX.mas_equalTo(bgView);
    }];
    
    UILabel *successLab = [UILabel labelWithText:@"支付成功" andTextColor:rgb(51,51,51) andName:nil andFontSize:19];
    successLab.numberOfLines = 1;
    [bgView addSubview:successLab];
    [successLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(icon.mas_bottom).mas_equalTo(15);
//        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.mas_equalTo(bgView);
    }];
    
    UILabel *nameLab = [UILabel labelWithText:@"您已购买<<课程名称>>，" andTextColor:rgb(51,51,51) andName:nil andFontSize:17];
    [bgView addSubview:nameLab];
    [nameLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(successLab.mas_bottom).mas_equalTo(30);
//        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.mas_equalTo(bgView);
    }];
    
    UILabel *nameLab2 = [UILabel labelWithText:@"请到 学习-我的课程 中查看" andTextColor:rgb(51,51,51) andName:nil andFontSize:17];
    [bgView addSubview:nameLab2];
    [nameLab2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameLab.mas_bottom).mas_equalTo(0);
//        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.mas_equalTo(bgView);
    }];
    
    UIButton *goStudyBtn = [[UIButton alloc] init];
    [goStudyBtn setTitle:@"去学习" forState:UIControlStateNormal];
    [goStudyBtn setBackgroundImage:LBImage(@"wk_pay_button") forState:UIControlStateNormal];
    goStudyBtn.titleLabel.font = [UIFont systemFontOfSize:19];
    [goStudyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [goStudyBtn addTarget:self action:@selector(clickGoStudyBtn:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:goStudyBtn];
    [goStudyBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(nameLab2.mas_bottom).mas_equalTo(35);
        make.height.mas_equalTo(40);
    }];
    
    UIButton *goHomeBtn = [[UIButton alloc] init];
    [goHomeBtn setTitle:@"回首页" forState:UIControlStateNormal];
    [goHomeBtn setBackgroundImage:LBImage(@"wk_pay_button_blue") forState:UIControlStateNormal];
    goHomeBtn.titleLabel.font = [UIFont systemFontOfSize:19];
    [goHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [goHomeBtn addTarget:self action:@selector(clickHomeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:goHomeBtn];
    [goHomeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(goStudyBtn.mas_bottom).mas_equalTo(35);
        make.height.mas_equalTo(40);
    }];
    
    if ([self.addType isEqualToString:@"1"]) {
        [MBProgressHUD showSuccess:self.addInfo toView:self.view];
    }
}
#pragma mark - 去学习
- (void)clickGoStudyBtn:(UIButton *)sender{

    if ([self.type isEqualToString:@"2"]) {
        //跳转到详情页，从第一个控制开始计算（不是从后面的控制器开始计算）
        UIViewController *controller = self.navigationController.viewControllers[2];[self.navigationController popToViewController:controller animated:YES];
    }else{
        //跳转到详情页，从第一个控制开始计算（不是从后面的控制器开始计算）
        UIViewController *controller = self.navigationController.viewControllers[1];[self.navigationController popToViewController:controller animated:YES];
    }

    
}
#pragma mark - 去首页
- (void)clickHomeBtn:(UIButton *)sender{
    
    //这里 首页  进入  可以返回首页  可以正常返回
    //如果是在我的订单里就不能返回首页了   解决 直接返回根视图控制器
//    for (UIViewController *controller in self.navigationController.viewControllers) {
//        if ([controller isKindOfClass:[HomeViewController class]]) {
//            HomeViewController *vc =(HomeViewController *)controller;
//            [self.navigationController popToViewController:vc animated:YES];
//        }
//    }
    [self.navigationController popToRootViewControllerAnimated:YES];
    

}
@end
